<?php
/*
Autor: Marek Křivan
(c) 2009 
*/
if(intval($_SESSION['rank']) < 2){
	exit(WRONG_PERMISSIONS);
}
$id_tematu = 1 * $q[2];
$seo = ($GLOBALS['seo']) ? '' : 'index.php?q=';
$query = $GLOBALS['db']->query("SELECT forum,skupina,jmeno,zamknuto,dulezite FROM " . $GLOBALS['db_prefix'] ."forum_temata WHERE id = '$id_tematu';");
         while ($row = $query->fetch_array()) {
        if(empty($row)) {

        	echo "<meta http-equiv=\"refresh\" content=\"2;".$GLOBALS['url'].$seo."forum\" />"; echo("Toto fórum nebylo nalezeno! <a href=\"".$GLOBALS['url']."index.php?q=forum\">Zpět</a>.");
		}


       
        $id_fora = $row[0];
        $id_skupiny = $row[1];
        $jmeno_tematu = stripslashes($row[2]);
        $zamknuto = $row[3];
        $dulezite = $row[4];
        
        if(($q[4] == "1") && ($_SESSION['rank'] >= 2)) {
                $presun_id = 1 * $q[4];
                $query = $GLOBALS['db']->query("SELECT jmeno,id FROM " . $GLOBALS['db_prefix'] ."forum_fora ORDER BY jmeno;");
               while ($row = $query->fetch_array()) {
                        $zobraz_form .= "<option value=\"".$row['id']."\">".$row['jmeno']."</option>";
                }
                $zobraz_form = "<form action=\"".$GLOBALS['url'].$seo."forum/action_presun/$id_tematu\" method=\"post\"><fieldset><legend>Přesunout téma</legend><label>Vyberte fórum, kam chcete téma přesunout:</label><select name=\"forum_presun\">".$zobraz_form."</select><input type=\"hidden\" name=\"tema_presun\" value=\"".$id_tematu."\"><br /><br /><input type=\"submit\" name=\"presunout\" value=\"Přesunout\"><br /><br /></fieldset></form>";
        } else
        if((isset($_POST['presunout'])) && ($_SESSION['rank'] >= 2)) {
                $posledni = date("U");
                $forum_presun = 1 * $_POST['forum_presun'];
                $tema_presun = 1 * $_POST['tema_presun'];
                $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_temata SET forum = '$forum_presun', posledni = '$posledni' WHERE id = '$tema_presun';");
                $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_prispevky SET forum = '$forum_presun' WHERE tema = '$tema_presun';");
                $prispevku = mysql_affected_rows();
                $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_fora SET prispevku = prispevku - '$prispevku', temat = temat - 1 WHERE id = '$id_fora';");
                $query = $GLOBALS['db']->query("UPDATE " . $GLOBALS['db_prefix'] ."forum_fora SET prispevku = prispevku + '$prispevku', temat = temat + 1 WHERE id = '$forum_presun';");
                echo "<meta http-equiv=\"refresh\" content=\"1;".$GLOBALS['url'].$seo."forum/dues/".$id_tematu."/1\" />";
        } 
        } 
echo $zobraz_form;
?>
